// 指标细则
var GoalDetail = Ext.data.Record.create([{
	name : 'id',
	mapping : 'id',
	type : 'int'
}, {
	name : 'categoryId',
	mapping : 'categoryId',
	type : 'int'
},{
	name : 'content',
	mapping : 'content',
	type : 'string'
},{
	name : 'point',
	mapping : 'point',
	type : 'float'
},{
	name : 'spec',
	mapping : 'spec',
	type : 'string'
}, {
	name : 'ordering',
	mapping : 'ordering',
	type : 'float'
}, {
	name : 'memo',
	mapping : 'memo',
	type : 'string'
},{
	name : 'checkOrgId',
	mapping : 'checkOrgId',
	type : 'int'
},{
	name : 'percent',
	mapping : 'percent',
	type : 'float'
},{
	name : 'categoryIdPath',
	mapping : 'categoryIdPath',
	type : 'string'
},{
	name : 'categoryNamePath',
	mapping : 'categoryNamePath',
	type : 'string'
},{
	name : 'status',
	mapping : 'status',
	type : 'string'
},{
	name : 'year',
	mapping : 'year',
	type : 'int'
}]);

var ds_goaldetail_select = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/supervise/biz/goaldetail/findAllGoalDetail.action'
	}),
//	autoLoad: true,
	reader : new Ext.data.JsonReader({
		root : 'root',
		successProperty :'success'
	}, [{
		name : 'id',
		type : 'int'
	}, {
		name : 'categoryId',
		type : 'int'
	},{
		name : 'content',
		type : 'string'
	},{
		name : 'point',
		type : 'float'
	},{
		name : 'spec',
		type : 'string'
	}, {
		name : 'ordering',
		type : 'float'
	}, {
		name : 'memo',
		type : 'string'
	},{
		name : 'checkOrgId',
		type : 'int'
	},{
		name : 'percent',
		type : 'float'
	},{
		name : 'categoryIdPath',
		type : 'string'
	},{
		name : 'categoryNamePath',
		type : 'string'
	},{
		name : 'status',
		type : 'string'
	},{
		name : 'year',
		type : 'int'
	}])
});

// row expander
var expander_content = new Ext.ux.grid.RowExpander({
    tpl : new Ext.Template(
        '<p><b>考核内容:</b> {content}</p><br>',
        '<p><b>评分标准:</b> {spec}</p>'
    )
});
var cm_goaldetail = new Ext.grid.ColumnModel([
	expander_content,
	new Ext.grid.RowNumberer({header : '序号', width : 40, dataIndex: 'id'}),
	{id: 'categoryId',header: "指标目录", width: 180, hidden: true, dataIndex: 'categoryId'},
    {id: 'categoryNamePath',header: "指标目录路径", width: 180, sortable: true, dataIndex: 'categoryNamePath'},
	{id: 'content',header: "指标考核内容", width: 200, sortable: true, dataIndex: 'content'},
	{id: 'point',header: "标准分值", width: 60, sortable: true, dataIndex: 'point'},
	{id: 'spec',header: "评分标准", width: 160, sortable: true, dataIndex: 'spec'},
	{id: 'ordering',header: "排序", width: 100, hidden : true, dataIndex: 'ordering'},
	{id: 'memo',header: "备注", width: 160, hidden : true, dataIndex: 'memo'},
	{id: 'checkOrgId',header: "考核责任单位", width: 100, sortable: true, dataIndex: 'checkOrgId',
		renderer: function(value, p, r) {
			var ret = '';
			var size = ds_org_select.getCount();
			for (var i = 0; i < size; i++) {
				var record = ds_org_select.getAt(i);
				var id = record.get('id');
				if (id == value) {
					ret = record.get('name');
					break;
				}
			}
			return (ret == '' || ret == null) ? value : ret;
		}},
	{id: 'percent',header: "换算关系(%)", width: 80, hidden: true, dataIndex: 'percent'},
    {id: 'categoryIdPath',header: "指标目录id 路径 ", width: 80, hidden : true, dataIndex: 'categoryIdPath'},
   // {id: 'status',header: "状态 ", width: 60, hidden : false, dataIndex: 'status', renderer: fun_getGoalStatus},
	{id: 'year',header: "考核年度",hidden : true, width: 120, dataIndex: 'year'}
]);
//考核内容 分值 考核责任单位 指标目录和指标细则换算关系（默认100%）指标目录路径 排序
var window_add_goaldetail = new Ext.Window({
			title : '添加指标细则',
			width : 480,
			height : 640,
			resizable : false,
			autoHeight : true,
			modal : true,
			closeAction : 'hide',
			listeners : {
				'hide' : function() {
					var frm = Ext.getCmp("form_add_goaldetail").getForm();
					frm.reset();
					frm.findField('goalDetail.categoryId').setRawValue("");
				}
			},
			items : [new Ext.FormPanel({
						id : 'form_add_goaldetail',
						labelWidth : 100,
						labelAlign : 'right',
						url : '/supervise/biz/goaldetail/saveGoalDetail.action',
						method : 'post',
						border : false,
						baseCls : 'x-plain',
						bodyStyle : 'padding:5px 5px 0',
						defaults : {
							anchor : '90%',
							width : 240,
							msgTarget : 'side' // 验证信息显示右边
						},
						defaultType : 'textfield',
						items : [{
									xtype : 'hidden',
									name : 'goalDetail.id'
								},{
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核年度',
									hiddenName : 'goalDetail.year',
									valueField : 'value',
									displayField : 'text',
									value: check_year,
									mode : 'local',
									store : ds_year_select,
									value : select_year,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									width : 80,
									typeAhead : true,
									readOnly : true,
									triggerAction : 'all',
									loadingText : '加载中...',
									emptyText : '请选择考核年度',
									listeners : {
										'select' : function(combo, record, index) {
											select_year = combo.getValue();
											var combotree = Ext.getCmp("combotree_add");
											combotree.clearValue();
											try{
												var root = combotree.tree.getRootNode();
												root.reload();
											}catch(e){}
										}
									}
								}, {
									id : 'combotree_add',
									xtype : 'combotree',
									fieldLabel : '<span style="color: red">*&nbsp;</span>指标目录',
									hiddenName : 'goalDetail.categoryId',
									selectNodeModel:'leaf', //只有选叶子时，才设置值  
									allowBlank : true,
									tree : {
										xtype:'treepanel',
										rootVisible : false,
										autoScroll : true,
										firstLoad : true,
										loadingText : '加载中...',
										loader : new Ext.tree.TreeLoader(),
										root : new Ext.tree.AsyncTreeNode(),
										listeners : {
											'beforeload' : function(node) {
												var	checkYear = select_year;
												var nodeId = Ext.num(node.id, null);
												if (Ext.isNumber(nodeId)) {
													this.loader.dataUrl = '/supervise/biz/goalcategory/getChildrenById.action?checkYear='
															+ checkYear + '&nodeId=' + node.id;
												} else {
													this.loader.dataUrl = "/supervise/biz/goalcategory/getRoot.action?checkYear=" + checkYear;
												}
											}
										}
							    	},
							    	listeners:{  
							            beforeselect: function(comboxtree,newNode,oldNode){//选择树结点设值之前的事件  
							                 
							            },  
							            select: function(comboxtree,newNode,oldNode){//选择树结点设值之后的事件  
							                var frm = Ext.getCmp("form_add_goaldetail").getForm();
							                var percent = newNode.attributes.percent;
							            	frm.findField('goalDetail.percent').setValue(percent);
							            	frm.findField('goalDetail.categoryIdPath').setValue(newNode.getPath("id"));
											frm.findField('goalDetail.categoryNamePath').setValue(newNode.getPath("text"));
											var checkOrgId = Ext.num(newNode.attributes.checkOrgId, 0);
											if(checkOrgId != 0){
												frm.findField('goalDetail.checkOrgId').setValue(checkOrgId);
											}
											var isAdded = Ext.num(newNode.attributes.isAdded, 0);
//											frm.findField('goalDetail.point').clearInvalid();
											if(isAdded == 1){
												frm.findField('goalDetail.point').allowBlank = true;
											} else {
												frm.findField('goalDetail.point').allowBlank = false;
											}
							            }, 
							            afterchange: function(comboxtree,newNode,oldNode){//选择树结点设值之后，并当新值和旧值不相等时的事件  
							                  //...  
							            }  
							     	}  
								}, {
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核内容',
									name : 'goalDetail.content',
									height : 200,
									allowBlank : false
								},{
									xtype : 'numberfield',
									fieldLabel : '<span style="color: red">*&nbsp;</span>标准分值',
									name : 'goalDetail.point',
									allowBlank : false,
									maxLength : 20
								},{
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>评分标准',
									name : 'goalDetail.spec',
									allowBlank : false
								},{
									xtype : 'hidden',
//									fieldLabel : '排序',
									name : 'goalDetail.ordering',
									value : 4
								}, {
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核责任单位',
									hiddenName : 'goalDetail.checkOrgId',
									valueField : 'id',
									displayField : 'name',
									mode : 'remote',
									store : ds_org_select,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									triggerAction : 'all',
									loadingText : '加载中...',
									emptyText : '请选择部门'
								},{
									xtype : 'hidden',
									name : 'goalDetail.percent',
									value : 1
								}, {
									xtype : 'textarea',
									fieldLabel : '备注',
									name : 'goalDetail.memo'
								},{ 
									xtype : 'hidden',
//									fieldLabel : '指标目录id 路径',
									name : 'goalDetail.categoryIdPath'
								},{ 
									xtype : 'hidden',
//									fieldLabel : '考核指标目录名称路径',
									name : 'goalDetail.categoryNamePath'
								}],
						buttonAlign : 'center',
						minButtonWidth : 60,
						buttons : [{
									text : '添加',
									handler : function(btn) {
										var frm = Ext.getCmp("form_add_goaldetail").getForm();
										if (frm.isValid()) {
											btn.disable();
											var cnfield = frm.findField('goalDetail.content');
											frm.submit({
														waitTitle : '请稍候',
														waitMsg : '正在提交表单数据,请稍候...',
														success : function(form, action) {
															var store = grid_goaldetail.getStore();
															var goaldetail = new GoalDetail({
																		id : action.result.id,
																		categoryId : form.findField('goalDetail.categoryId').getValue(),
																		content : cnfield.getValue(),
																		point : form.findField('goalDetail.point').getValue(),
																		spec : form.findField('goalDetail.spec').getValue(),
																		ordering : form.findField('goalDetail.ordering').getValue(),
																		memo : form.findField('goalDetail.memo').getValue(),
																		checkOrgId : form.findField('goalDetail.checkOrgId').getValue(),
																		percent : form.findField('goalDetail.percent').getValue(),
																		categoryIdPath : form.findField('goalDetail.categoryIdPath').getValue(),
																		categoryNamePath : form.findField('goalDetail.categoryNamePath').getValue(),
																		year : form.findField('goalDetail.year').getValue()
																	}); 
															store.insert(0, [goaldetail]);
															grid_goaldetail.getView().refresh();
															frm.reset();
															btn.enable();
															window_add_goaldetail.hide();
														},
														failure : function() {
															Ext.Msg.show({
																		title : '错误提示',
																		msg : '"' + cnfield.getValue() + '" ' + '名称可能已经存在!',
																		buttons : Ext.Msg.OK,
																		fn : function() {
																			cnfield.focus(true);
																			btn.enable();
																		},
																		icon : Ext.Msg.ERROR
																	});
														}
													});
										}
									}
								}, {
									text : '重置',
									handler : function() {
										Ext.getCmp("form_add_goaldetail").getForm().reset();
									}
								}, {
									text : '取消',
									handler : function() {
										window_add_goaldetail.hide();
									}
								}]
					})]
		});
		
var window_edit_goaldetail = new Ext.Window({
			title : '修改指标细则',
			width : 480,
			height : 640,
			resizable : false,
			autoHeight : true,
			modal : true,
			closeAction : 'hide',
			listeners : {
				'hide' : function() {
					this.setTitle('修改指标细则');
					Ext.getCmp("form_edit_goaldetail").getForm().reset();
				}
			},
			items : [new Ext.FormPanel({
						id : 'form_edit_goaldetail',
						labelWidth : 100,
						labelAlign : 'right',
						url : '/supervise/biz/goaldetail/saveGoalDetail.action',
						method : 'post',
						border : false,
						baseCls : 'x-plain',
						bodyStyle : 'padding:5px 5px 0',
						defaults : {
							anchor : '90%',
							width : 240,
							msgTarget : 'side' // 验证信息显示右边
						},
						defaultType : 'textfield',
						items : [{
									xtype : 'hidden',
									name : 'goalDetail.id'
								},{
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核年度',
									hiddenName : 'goalDetail.year',
									valueField : 'value',
									displayField : 'text',
									value: check_year,
									mode : 'local',
									store : ds_year_select,
									value : select_year,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									width : 80,
									typeAhead : true,
									readOnly : true,
									triggerAction : 'all',
									loadingText : '加载中...',
									emptyText : '请选择考核年度',
									listeners : {
										'select' : function(combo, record, index) {
											select_year = combo.getValue();
											var combotree = Ext.getCmp("combotree_edit");
											combotree.clearValue();
											try{
												var root = combotree.tree.getRootNode();
												root.reload();
											}catch(e){}
										}
									}
								}, {
									xtype : 'hidden',
									name : 'goalDetail.categoryId'
								} ,{
									id : 'combotree_edit',
									xtype : 'combotree',
									fieldLabel : '<span style="color: red">*&nbsp;</span>指标目录',
									hiddenName : 'edit.categoryId',
									selectNodeModel:'leaf', //只有选叶子时，才设置值  
									allowBlank : false,
									tree : {
										xtype:'treepanel',
										rootVisible : false,
										autoScroll : true,
										firstLoad : true,
										loadingText : '加载中...',
										loader : new Ext.tree.TreeLoader(),
										root : new Ext.tree.AsyncTreeNode(),
										listeners : {
											'beforeload' : function(node) {
												var	checkYear = select_year;
												var nodeId = Ext.num(node.id, null);
												if (Ext.isNumber(nodeId)) {
													this.loader.dataUrl = '/supervise/biz/goalcategory/getChildrenById.action?checkYear='
															+ checkYear + '&nodeId=' + node.id;
												} else {
													this.loader.dataUrl = "/supervise/biz/goalcategory/getRoot.action?checkYear=" + checkYear;
												}
											}
										}
							    	},
							    	listeners:{  
							            beforeselect: function(comboxtree,newNode,oldNode){//选择树结点设值之前的事件  
							                 
							            },  
							            select: function(comboxtree,newNode,oldNode){//选择树结点设值之后的事件  
							                var frm = Ext.getCmp("form_edit_goaldetail").getForm();
							                var percent = newNode.attributes.percent;
							                frm.findField('goalDetail.categoryId').setValue(newNode.id);
							            	frm.findField('goalDetail.percent').setValue(percent);
							            	frm.findField('goalDetail.categoryIdPath').setValue(newNode.getPath("id"));
											frm.findField('goalDetail.categoryNamePath').setValue(newNode.getPath("text"));
											var isAdded = Ext.num(newNode.attributes.isAdded, 0);
//											frm.findField('goalDetail.point').clearInvalid();
											if(isAdded == 1){
												frm.findField('goalDetail.point').allowBlank = true;
											} else {
												frm.findField('goalDetail.point').allowBlank = false;
											}
							            },  
							            afterchange: function(comboxtree,newNode,oldNode){//选择树结点设值之后，并当新值和旧值不相等时的事件  
//							            	var frm = Ext.getCmp("form_edit_goaldetail").getForm();
//							            	var nodeId = newNode.getPath("id");
//							            	alert(newNode.id);
//							                var s = nodeId.lastIndexOf("/");
//							                if(s != -1){
//							                	var id = nodeId.substr(s + 1);
//							                	if(Ext.num(id, 0) != 0){
//							                 		frm.findField('goalDetail.categoryId').setValue(id);
//							                	}
//							                }
							            }  
							     	}  
								}, {
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核内容',
									name : 'goalDetail.content',
									height : 200,
									allowBlank : false
								},{
									xtype : 'numberfield',
									fieldLabel : '<span style="color: red">*&nbsp;</span>标准分值',
									name : 'goalDetail.point',
									allowBlank : false,
									maxLength : 20
								},{
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>评分标准',
									name : 'goalDetail.spec',
									allowBlank : false
								},{
									xtype : 'hidden',
//									fieldLabel : '排序',
									name : 'goalDetail.ordering',
									value : 4
								}, {
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核责任单位',
									hiddenName : 'goalDetail.checkOrgId',
									valueField : 'id',
									displayField : 'name',
									mode : 'remote',
									store : ds_org_select,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									triggerAction : 'all',
									loadingText : '加载中...',
									emptyText : '请选择部门'
								},{
									xtype : 'hidden',
									name : 'goalDetail.percent',
									value : 1
								}, {
									xtype : 'textarea',
									fieldLabel : '备注',
									name : 'goalDetail.memo'
								},{ 
									xtype : 'hidden',
//									fieldLabel : '指标目录id 路径',
									name : 'goalDetail.categoryIdPath'
								},{ 
									xtype : 'hidden',
//									fieldLabel : '考核指标目录名称路径',
									name : 'goalDetail.categoryNamePath'
								}],
						buttonAlign : 'center',
						minButtonWidth : 60,
						buttons : [{
									text : '修改',
									handler : function(btn) {
										var frm = Ext.getCmp("form_edit_goaldetail").getForm();
										if (frm.isValid()) {
											btn.disable();
											var cnfield = frm.findField('goalDetail.content');
											frm.submit({
														waitTitle : '请稍候',
														waitMsg : '正在提交表单数据,请稍候...',
														success : function(form, action) {
															var record = grid_goaldetail.getSelectionModel().getSelected();
															// set value
															record.set("categoryId", frm.findField('goalDetail.categoryId').getValue());
															record.set("content", frm.findField('goalDetail.content').getValue());
															record.set("point", frm.findField('goalDetail.point').getValue());
															record.set("spec", frm.findField('goalDetail.spec').getValue());
															record.set("ordering", frm.findField('goalDetail.ordering').getValue());
															record.set("memo", frm.findField('goalDetail.memo').getValue());
															record.set("checkOrgId", frm.findField('goalDetail.checkOrgId').getValue());
															record.set("percent", frm.findField('goalDetail.percent').getValue());
															record.set("categoryIdPath", frm.findField('goalDetail.categoryIdPath').getValue());
															record.set("categoryNamePath", frm.findField('goalDetail.categoryNamePath').getValue());
															record.set("year", frm.findField('goalDetail.year').getValue());
															record.commit();
															frm.reset();
															btn.enable();
															window_edit_goaldetail.hide();
														},
														failure : function() {
															Ext.Msg.show({
																		title : '错误提示',
																		msg : '"' + cnfield.getValue() + '" ' + '名称可能已经存在!',
																		buttons : Ext.Msg.OK,
																		fn : function() {
																			cnfield.focus(true);
																			btn.enable();
																		},
																		icon : Ext.Msg.ERROR
																	});
														}
													});
										}
									}
								}, {
									text : '取消',
									handler : function() {
										window_edit_goaldetail.hide();
									}
								}]
					})]
		});
var btn_add_goaldetail = new Ext.Button({
			text : '添加',
			iconCls : 'icon-add',
			handler : function() {
				window_add_goaldetail.show(this);
				window_add_goaldetail.center();
			}
		});
var btn_edit_goaldetail = new Ext.Button({
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				if (!grid_goaldetail.checkOne()) {
					return;
				}
				window_edit_goaldetail.show(this);
				window_edit_goaldetail.center();
				var record = grid_goaldetail.getSelectionModel().getSelected();
				var frm = Ext.getCmp("form_edit_goaldetail").getForm();
				// set value
				frm.findField('goalDetail.id').setValue(record.get("id"));
				
				frm.findField('goalDetail.content').setValue(record.get("content"));
				frm.findField('goalDetail.point').setValue(record.get("point"));
				frm.findField('goalDetail.spec').setValue(record.get("spec"));
				frm.findField('goalDetail.ordering').setValue(record.get("ordering"));
				frm.findField('goalDetail.memo').setValue(record.get("memo"));
				frm.findField('goalDetail.checkOrgId').setValue(record.get("checkOrgId"));
				frm.findField('goalDetail.percent').setValue(record.get("percent"));
				frm.findField('goalDetail.categoryIdPath').setValue(record.get("categoryIdPath"));
				frm.findField('goalDetail.categoryNamePath').setValue(record.get("categoryNamePath"));
				frm.findField('goalDetail.year').setValue(record.get("year"));
				frm.findField('goalDetail.categoryId').setValue(record.get("categoryId"));
				try {
					frm.findField('edit.categoryId').setRawValue(record.get("categoryNamePath"));
				}catch (e){
					
				}
			}
		});
var btn_del_goaldetail = new Ext.Button({
			text : '删除',
			iconCls : 'icon-del',
			handler : function() {
				if (!grid_goaldetail.checkOne()){
					return;
				}
				var record = grid_goaldetail.getSelectionModel().getSelected();
//				var status = record.get("status");
//				if('audit_yes' == status || 'audit_no' == status){
//					Ext.MessageBox.alert("提示", "些指标已审核，不能删除！");
//					return;
//				}
				if (record) {
					Ext.Msg.confirm('确认删除', '你确定删除该条记录?', function(btn) {
								if (btn == 'yes') {
									Ext.Ajax.request({
												url : '/supervise/biz/goaldetail/deleteGoalDetail.action',
												params : {
													id : record.data.id
												},
												success : function() {
													grid_goaldetail.getStore().remove(record);
												},
												failure : function() {
													Ext.Msg.show({
																title : '错误提示',
																msg : '删除时发生错误!',
																buttons : Ext.Msg.OK,
																icon : Ext.Msg.ERROR
															});
												}
											});
								}
							});
				}
			}
		});
var btn_search_goaldetail = new Ext.Button({
	text : '查询',
	iconCls : 'icon-search',
	handler : function() {
		grid_goaldetail.render();
		ds_goaldetail.baseParams = {
			year : frm.findField('year').getValue(),
			categoryId : frm.findField('categoryId').getValue(),
			content : frm.findField('content').getValue(),
			checkOrgId :frm.findField('checkOrgId').getValue()
		};
		ds_goaldetail.load({
				params : {
					start : 0,
					limit : 20
				}
			});
	}
});
					
var ds_goaldetail = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/supervise/biz/goaldetail/findGoalDetailByPage.action'
	}),
	reader : new Ext.data.JsonReader({
			totalProperty : 'totalProperty',
			root : 'root'
		}, [{
			name : 'id',
			type : 'int'
		}, {
			name : 'categoryId',
			type : 'int'
		},{
			name : 'content',
			type : 'string'
		},{
			name : 'point',
			type : 'float'
		},{
			name : 'spec',
			type : 'string'
		}, {
			name : 'ordering',
			type : 'float'
		}, {
			name : 'memo',
			type : 'string'
		},{
			name : 'checkOrgId',
			type : 'int'
		},{
			name : 'percent',
			type : 'float'
		},{
			name : 'categoryIdPath',
			type : 'string'
		},{
			name : 'categoryNamePath',
			type : 'string'
		},{
			name : 'status',
			type : 'string'
		},{
		name : 'year',
		type : 'int'
	}])
});

var grid_goaldetail = new Ext.grid.GridPanel({
//			title : '指标细则',
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			viewConfig : {
				forceFit : true
			},
			region : 'center',
			cm : cm_goaldetail,
			sm : new Ext.grid.RowSelectionModel({
						singleSelect : true
					}),
			store : ds_goaldetail,
			autoExpandColumn : 'content',
			plugins: expander_content,
			tbar : [btn_add_goaldetail, '-', btn_edit_goaldetail, '-', btn_del_goaldetail],
			bbar : new Ext.PagingToolbar({
						pageSize : 20,
						store : ds_goaldetail,
						displayInfo : true,
						displayMsg : '第 {0} - {1} 条  共 {2} 条',
						refreshText : "刷新",
						emptyMsg : "没有记录"
					}),
			// 检测至少选择一个
			checkOne : function() {
				var selections = this.getSelectionModel().getSelections();
				if (selections.length == 0) {
					Ext.MessageBox.alert("提示", "请选择一条的记录！");
					return false;
				} else if (selections.length != 1) {
					Ext.MessageBox.alert("提示", "不能选择多行！");
					return false;
				}
				return true;
			},

			// 检测必须选择一个
			checkMany : function() {
				var selections = this.getSelectionModel().getSelections();
				if (selections.length == 0) {
					Ext.MessageBox.alert("提示", "请至少选择一条的记录！");
					return false;
				}
				return true;
			},
			listeners : {
				'render' : function(e) {
				ds_goaldetail.baseParams = {
							year : new Date().getFullYear()
						};
					ds_goaldetail.load({params : {
							start : 0,
							limit : 20
						}});
				}
			}

		});
var qpanel_goaldetail = new Ext.Panel({
//	title : '<h3 style="color:Green">请输入查询条件</h3>',
	height : 160,
	region : "north",
	baseCls:"x-plain",
	style:"padding:5px",
	layout:"column",
	items:[{
		columnWidth:0.6,
		layout:"form",
		frame : true,
		baseCls : 'x-plain',
		items : [new Ext.FormPanel({
			id: 'form_query_goaldetail',
			labelAlign : 'right',
			border : false,
			baseCls : 'x-plain',
			bodyStyle : 'padding:5px 5px 0',
			defaults : {
				anchor : '90%',
				width : 240,
				msgTarget : 'side' // 验证信息显示右边
			},
			defaultType : 'textfield',
			items:[{
					xtype : 'combo',
					fieldLabel : '<span style="color: red">*&nbsp;</span>考核年度',
					hiddenName : 'year',
					valueField : 'value',
					displayField : 'text',
					value: check_year,
					mode : 'local',
					store : ds_year_select,
//					value : select_year,
					selectOnFocus : true,
					editable : false,
					allowBlank : false,
					typeAhead : true,
					readOnly : true,
					triggerAction : 'all',
					loadingText : '加载中...',
					emptyText : '请选择考核年度',
					listeners : {
						'select' : function(combo, record, index) {
							select_year = combo.getValue();
							var root = catTree.getRootNode();
							root.reload();
						}
					}
				},{
					id : 'combotree_query',
					xtype : 'combotree',
					fieldLabel : '指标目录',
					hiddenName : 'goalDetail.categoryId',
					selectNodeModel:'leaf', //只有选叶子时，才设置值  
					allowBlank : false,
					tree : {
						xtype:'treepanel',
						rootVisible : false,
						autoScroll : true,
						firstLoad : true,
						loadingText : '加载中...',
						loader : new Ext.tree.TreeLoader(),
						root : new Ext.tree.AsyncTreeNode(),
						listeners : {
							'beforeload' : function(node) {
									var checkYear = select_year;
									var nodeId = Ext.num(node.id, null);
									if (Ext.isNumber(nodeId)) {
										this.loader.dataUrl = '/supervise/biz/goalcategory/getChildrenById.action?checkYear='
												+ checkYear + '&nodeId=' + node.id;
									} else {
										this.loader.dataUrl = "/supervise/biz/goalcategory/getRoot.action?checkYear=" + checkYear;
									}
								}
							}
				    	},
				    	listeners:{  
				            beforeselect: function(comboxtree,newNode,oldNode){//选择树结点设值之前的事件  
			            },  
			            select: function(comboxtree,newNode,oldNode){//选择树结点设值之后的事件  
			            	var frm = Ext.getCmp("form_query_goaldetail").getForm();
							frm.findField('categoryId').setValue(newNode.id);
			            },  
			            afterchange: function(comboxtree,newNode,oldNode){//选择树结点设值之后，并当新值和旧值不相等时的事件  
			            }  
			     	}  
				},{
					xtype : 'hidden',
					name : 'categoryId'
				}, {
					fieldLabel : '考核内容',
					name : 'content'
				}, {
					xtype : 'combo',
					fieldLabel : '考核责任单位',
					hiddenName : 'checkOrgId',
					valueField : 'id',
					displayField : 'name',
					mode : 'remote',
					store : ds_org_select,
	//						anchor : '100%',
					selectOnFocus : true,
					editable : false,
					allowBlank : true,
					triggerAction : 'all',
					loadingText : '加载中...',
					emptyText : '请选择部门'
				}],
			buttonAlign : 'center',
			minButtonWidth : 60,
			buttons : [{
						text : '查询',
						handler : function(btn) {
							var frm = btn.ownerCt.ownerCt.getForm();
							ds_goaldetail.baseParams = {
								year : frm.findField('year').getValue(),
								categoryId : frm.findField('categoryId').getValue(),
								content : frm.findField('content').getValue(),
								checkOrgId :frm.findField('checkOrgId').getValue()
							};
							ds_goaldetail.load({params : {
								start : 0,limit : 20
							}});}
					},{
						text : '重置',
						handler : function() { 
							var frm = Ext.getCmp('form_query_goaldetail').getForm();
							frm.reset();
							frm.findField('goalDetail.categoryId').setRawValue("");
						}
					}]
		})]
	}]
});

var query_goaldetail =  new Ext.Panel({
	frame : false,
	region : 'center',
	labelWidth : 65,
	title : '指标细则管理',
	labelPad : 45,
	buttonAlign : 'center',
	layout : 'border',
	items : [qpanel_goaldetail, grid_goaldetail]
});	
var p_goaldetail = {
	id : 'goaldetail-panel',
	border : false,
	layout : 'border',
	items : [query_goaldetail]
}; 